package logic

import (
	"context"
	"everyone/C/rpc_C/model/mysql"

	"everyone/C/rpc_C/everyone"
	"everyone/C/rpc_C/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *everyone.GoodsListRequest) (*everyone.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	list, err := g.Find(in.Page, in.PageSize)
	if err != nil {
		logx.Error("商品信息接收失败")
	}
	var goodslist []*everyone.GoodsItem
	for _, v := range list {
		goodslist = append(goodslist, &everyone.GoodsItem{
			GoodsId:    int64(v.ID),
			GoodsTitle: v.GoodsTitle,
			GoodsPrice: float32(v.GoodsPrice),
			GoodsNum:   v.GoodsNum,
			GoodsImage: v.GoodsImage,
			GoodsLike:  v.GoodsLike,
		})
	}
	return &everyone.GoodsListResponse{
		List: goodslist,
	}, nil
}
